package com.tjsinfo.tjsoa.reminded.dao;

import com.tjsinfo.tjsoa.reminded.vo.TSystemReminded;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Criteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;

/**
 * A data access object (DAO) providing persistence and search support for
 * TSystemReminded entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.oa.system.reminded.TSystemReminded
 * @author MyEclipse Persistence Tools
 */

public class TSystemRemindedDao extends HibernateDaoSupport implements ITSystemRemindedDao {
	
	private static final Log log = LogFactory.getLog(TSystemRemindedDao.class);
	public void save(TSystemReminded transientInstance) {
		log.debug("saving TSystemReminded instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TSystemReminded persistentInstance) {
		log.debug("deleting TSystemReminded instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TSystemReminded findById(java.lang.Integer id) {
		log.debug("getting TSystemReminded instance with id: " + id);
		try {
			TSystemReminded instance = (TSystemReminded) getHibernateTemplate()
					.get("com.tjsinfo.tjsoa.reminded.vo.TSystemReminded", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public TSystemReminded findByName(java.lang.String name) {
		log.debug("getting TSystemReminded instance with name: " + name);
		try {
			TSystemReminded instance = (TSystemReminded) getHibernateTemplate()
					.get("com.tjsinfo.tjsoa.reminded.vo.TSystemReminded", name);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public TSystemReminded findByOrganize(java.lang.String Organize) {
		log.debug("getting TSystemReminded instance with organizeid: " + Organize);
		try {
			TSystemReminded instance = (TSystemReminded) getHibernateTemplate()
					.get("com.tjsinfo.tjsoa.reminded.vo.TSystemReminded", Organize);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TSystemReminded instance) {
		log.debug("finding TSystemReminded instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TSystemReminded instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TSystemReminded as model where model."
					+ propertyName + "= ? order by id desc";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findByRemind(String idList, Object value,String memo, Object values) {
		Session session=getSession();
		log.debug("finding TSystemReminded instance with property: "
				+ idList + ", value: " + value + ", property:" + memo +",value:"+values);
		try {
			Criteria criteria = getSession().createCriteria(TSystemReminded.class);
			criteria.add(Expression.like(idList, value));
			criteria.add(Expression.not(Expression.like(memo, values)));
			criteria.addOrder(Order.desc("id"));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByLike(String likeName, Object value) {
		log.debug("finding TSystemReminded instance with property: "
				+ likeName + ", value: " + value);
		try {
			Criteria criteria = getSession().createCriteria(TSystemReminded.class);
			criteria.add(Expression.like(likeName, value));
			criteria.addOrder(Order.desc("id"));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findByPropertyAndProperty(String propertyName, Object value,String propertyNames, Object values) {
		Session session=getSession();
		log.debug("finding TSystemReminded instance with property: "
				+ propertyName + ", value: " + value + ", property:" + propertyNames +",value:"+values);
		try {
			Criteria criteria = getSession().createCriteria(TSystemReminded.class);
			criteria.add(Expression.like(propertyName, value));
			criteria.add(Expression.like(propertyNames, values));
			criteria.addOrder(Order.desc("id"));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List findAll() {
		log.debug("finding all TSystemReminded instances");
		try {
			String queryString = "from TSystemReminded";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TSystemReminded merge(TSystemReminded detachedInstance) {
		log.debug("merging TSystemReminded instance");
		try {
			TSystemReminded result = (TSystemReminded) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TSystemReminded instance) {
		log.debug("attaching dirty TSystemReminded instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TSystemReminded instance) {
		log.debug("attaching clean TSystemReminded instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	public void update(TSystemReminded transientInstance) {
		log.debug("saving TSystemReminded instance");
		try {
			this.getHibernateTemplate().update(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}	
	
	public void delete(Integer id) {
		log.debug("deleting TSystemReminded instance");
		try {			
			TSystemReminded tdwt = (TSystemReminded)this.getHibernateTemplate().load(TSystemReminded.class, id);
			getHibernateTemplate().delete(tdwt);
			log.debug("Delete successful");
		} catch (RuntimeException re) {
			log.error("Delete failed", re);
			throw re;
		}
	}	

}